version: '2.1'

x-define-image: &image
    image: ${IMAGE}

x-define-env: &env
    environment:
        - TZ=Asia/Shanghai
        - http_proxy=
        - https_proxy=
        - HTTP_PROXY=
        - HTTPS_PROXY=

x-define-servernode: &servernode
    <<: [*image, *env]
    command: /bin/sh /cfs/script/start.sh
    restart: on-failure
    privileged: true
x-define-master: &master
    <<: *servernode
    ports:
        - "5901"
        - "5902"
        - "17010"
        - "17020"
        - 9500
x-define-metanode: &metanode
    <<: *servernode
    ports:
        - "17210"
        - "17220"
        - "17230"
        - "17240"
        - 9500
x-define-datanode: &datanode
    <<: *servernode
    ports:
        - "17310"
        - "17320"
        - "17330"
        - "17340"
        - 9500
x-define-objectnode: &objectnode
    <<: *servernode
    ports:
        - "80"
        - 9500
x-define-lcnode: &lcnode
    <<: *servernode
    ports:
        - "17410"
        - 9500

x-define-command: &command
    <<: [*image, *env]
    volumes:
        - ../:${CFSROOT}


networks:
    extnetwork:
      ipam:
         config:
         - subnet: 192.168.0.0/24
           gateway: 192.168.0.1

services:
    monitor:
        <<: *image
        depends_on:
            - consul
            - prometheus
            - grafana
        networks:
            extnetwork:

    servers:
        <<: *image
        depends_on:
            - master1
            - master2
            - master3
            - metanode1
            - metanode2
            - metanode3
            - metanode4
            - datanode1
            - datanode2
            - datanode3
            - datanode4
            - objectnode1
            - objectnode2
            - objectnode3
            - lcnode1
            - lcnode2
            - lcnode3
            - console1
            - nginx
        networks:
            extnetwork:

    master1:
        <<: *master
        volumes:
            - ${DiskPath:-./docker_data}/master1/data:/cfs/data
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/master1/log:/cfs/log
            - ./conf/master1.json:/cfs/conf/master.json
            - ./script/start_master.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.11
    master2:
        <<: *master
        volumes:
            - ${DiskPath:-./docker_data}/master2/data:/cfs/data
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/master2/log:/cfs/log
            - ./conf/master2.json:/cfs/conf/master.json
            - ./script/start_master.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.12
    master3:
        <<: *master
        volumes:
            - ${DiskPath:-./docker_data}/master3/data:/cfs/data
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/master3/log:/cfs/log
            - ./conf/master3.json:/cfs/conf/master.json
            - ./script/start_master.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.13

    metanode1:
        <<: *metanode
        volumes:
            - ${DiskPath:-./docker_data}/metanode1/data:/cfs/data
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/metanode1/log:/cfs/log
            - ./conf/metanode.json:/cfs/conf/metanode.json
            - ./script/start_meta.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.21
    metanode2:
        <<: *metanode
        volumes:
            - ${DiskPath:-./docker_data}/metanode2/data:/cfs/data
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/metanode2/log:/cfs/log
            - ./conf/metanode.json:/cfs/conf/metanode.json
            - ./script/start_meta.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.22
    metanode3:
        <<: *metanode
        volumes:
            - ${DiskPath:-./docker_data}/metanode3/data:/cfs/data
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/metanode3/log:/cfs/log
            - ./conf/metanode.json:/cfs/conf/metanode.json
            - ./script/start_meta.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.23
    metanode4:
        <<: *metanode
        volumes:
            - ${DiskPath:-./docker_data}/metanode4/data:/cfs/data
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/metanode4/log:/cfs/log
            - ./conf/metanode.json:/cfs/conf/metanode.json
            - ./script/start_meta.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.24

    datanode1:
        <<: *datanode
        volumes:
            - ${DiskPath:-./docker_data}/datanode1/disk:/cfs/disk
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/datanode1/log:/cfs/log
            - ./conf/datanode.json:/cfs/conf/datanode.json
            - ./script/start_datanode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.31
    datanode2:
        <<: *datanode
        volumes:
            - ${DiskPath:-./docker_data}/datanode2/disk:/cfs/disk
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/datanode2/log:/cfs/log
            - ./conf/datanode.json:/cfs/conf/datanode.json
            - ./script/start_datanode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.32
    datanode3:
        <<: *datanode
        volumes:
            - ${DiskPath:-./docker_data}/datanode3/disk:/cfs/disk
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/datanode3/log:/cfs/log
            - ./conf/datanode.json:/cfs/conf/datanode.json
            - ./script/start_datanode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.33
    datanode4:
        <<: *datanode
        volumes:
            - ${DiskPath:-./docker_data}/datanode4/disk:/cfs/disk
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/datanode4/log:/cfs/log
            - ./conf/datanode.json:/cfs/conf/datanode.json
            - ./script/start_datanode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.34

    objectnode1:
        <<: *objectnode
        volumes:
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/objectnode1/log:/cfs/log
            - ./conf/objectnode.json:/cfs/conf/objectnode.json
            - ./script/start_objectnode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.41
    objectnode2:
        <<: *objectnode
        volumes:
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/objectnode2/log:/cfs/log
            - ./conf/objectnode.json:/cfs/conf/objectnode.json
            - ./script/start_objectnode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.42
    objectnode3:
        <<: *objectnode
        volumes:
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/objectnode3/log:/cfs/log
            - ./conf/objectnode.json:/cfs/conf/objectnode.json
            - ./script/start_objectnode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.43

    lcnode1:
        <<: *lcnode
        volumes:
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/lcnode1/log:/cfs/log
            - ./conf/lcnode.json:/cfs/conf/lcnode.json
            - ./script/start_lcnode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.61
    lcnode2:
        <<: *lcnode
        volumes:
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/lcnode2/log:/cfs/log
            - ./conf/lcnode.json:/cfs/conf/lcnode.json
            - ./script/start_lcnode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.62
    lcnode3:
        <<: *lcnode
        volumes:
            - ./bin:/cfs/bin:ro
            - ${DiskPath:-./docker_data}/lcnode3/log:/cfs/log
            - ./conf/lcnode.json:/cfs/conf/lcnode.json
            - ./script/start_lcnode.sh:/cfs/script/start.sh
        networks:
            extnetwork:
                ipv4_address: 192.168.0.63

    console1:
        <<: *servernode
        ports:
          - "80"
        volumes:
          - ./bin:/cfs/bin:ro
          - ${DiskPath:-./docker_data}/console/log:/cfs/log
          - ./conf/console.json:/cfs/conf/console.json
          - ./script/start_console.sh:/cfs/script/start.sh
        networks:
          extnetwork:
            ipv4_address: 192.168.0.50

    client:
        <<: [*image, *env]
        ports:
            - 9500
            - 17410:17410
        volumes:
            - ./bin:/cfs/bin:ro
            - ./conf/hosts:/etc/hosts:ro
            - ./conf/client.json:/cfs/conf/client.json
            - ${DiskPath:-./docker_data}/client/log:/cfs/log
            - ./script/run_test.sh:/cfs/script/start.sh
            - ./script/start_client.sh:/cfs/script/start_client.sh
            - ./ltp/runtest/fs:/opt/ltp/runtest/fs
            - ./s3tests:/opt/s3tests:ro
        privileged: true
        devices:
            - /dev/fuse:/dev/fuse:rwm
        command: /bin/bash /cfs/script/start.sh
        networks:
            extnetwork:


    client_ltp:
        <<: *env
        image: ${IMAGELTP}
        ports:
            - 9500
            - 17410:17410
        volumes:
            - ./bin:/cfs/bin:ro
            - ./conf/hosts:/etc/hosts:ro
            - ./conf/client.json:/cfs/conf/client.json
            - ${DiskPath:-./docker_data}/client/log:/cfs/log
            - ./script/run_test.sh:/cfs/script/start.sh
            - ./script/start_client.sh:/cfs/script/start_client.sh
            - ./ltp/runtest/fs:/opt/ltp/runtest/fs
            - ./s3tests:/opt/s3tests:ro
        privileged: true
        devices:
            - /dev/fuse:/dev/fuse:rwm
        command: /bin/bash /cfs/script/start.sh -ltp
        networks:
            extnetwork:

    consul:
        <<: *env
        image: consul:1.5
        ports:
            - 8500:8500
        volumes:
            - ./monitor:/monitor
        privileged: true
        networks:
            extnetwork:
                ipv4_address: 192.168.0.101

    prometheus:
        <<: *env
        image: prom/prometheus
        ports:
            - 9090:9090
        volumes:
            - ./monitor/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
        privileged: true
        networks:
            extnetwork:
                ipv4_address: 192.168.0.102

    grafana:
        image: grafana/grafana:6.4.4
        environment:
            - GF_SECURITY_ADMIN_PASSWORD=123456
            - http_proxy=
            - https_proxy=
            - HTTP_PROXY=
            - HTTPS_PROXY=
        ports:
            - 3000:3000
        volumes:
            - ./monitor/grafana/grafana.ini:/etc/grafana/grafna.ini
            - ./monitor/grafana/provisioning:/etc/grafana/provisioning
            - ./monitor/grafana/init.sh:/grafana/init.sh
        privileged: true
        #command: /bin/bash
        networks:
            extnetwork:
                ipv4_address: 192.168.0.103

    nginx:
        <<: *env
        image: nginx:1.17.8
        ports:
            - "80:80"
        volumes:
            - ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
        command: /bin/bash -c "nginx -g 'daemon off;'"
        restart: on-failure
        privileged: true
        networks:
            extnetwork:
                ipv4_address: 192.168.0.104

    prepare:
        <<: *command
        command:
            - bash
            - "-c"
            - >-
                set -e;
                tar -zxf /go/rocksdb_libs.tar.gz -C ${CFSROOT}/build

    format:
        <<: *command
        command: /bin/bash ${CFSROOT}/docker/script/run_format.sh

    build:
        <<: *image
        volumes:
            - ../:${CFSROOT}
            - ./script/build.sh:/cfs/script/build.sh
        command: /bin/bash /cfs/script/build.sh

    unit_test:
        <<: *command
        command:
            - bash
            - "-c"
            - >-
                set -e;
                mkdir -p ${CFSROOT}/docker/bin &&
                cd ${CFSROOT} && make testcover
        environment:
            - TZ=Asia/Shanghai
            - DOCKER_TESTING_LOG_OFF="on"
            - http_proxy=
            - https_proxy=
            - HTTP_PROXY=
            - HTTPS_PROXY=

    build_libsdkpre:
        <<: *command
        command:
            - bash
            - "-c"
            - >-
                set -e;
                cd ${CFSROOT} && make libsdkpre

    goreleaser:
        <<: *command
        command:
            - bash
            - "-c"
            - >-
                set -e;
                cd ${CFSROOT} &&
                /go/bin/goreleaser release --skip-publish --clean

    bs_gofumpt:
        <<: *command
        command:
            - bash
            - "-c"
            - >-
                set -e;
                cd ${CFSROOT}/blobstore && go vet -trimpath ./... &&
                /go/bin/gofumpt -l -w . && git diff --exit-code

    bs_golint:
        <<: *command
        command:
            - bash
            - "-c"
            - >-
                set -e;
                cd ${CFSROOT}/blobstore &&
                /go/bin/golangci-lint run --timeout 10m --issues-exit-code=1 -D errcheck -E bodyclose ./...

    gosec:
        <<: *command
        command:
            - bash
            - "-c"
            - >-
                set -e;
                cd ${CFSROOT} &&
                /go/bin/gosec -severity=high -exclude-dir=depends -exclude-dir=vendor -exclude-dir=autofs -exclude=G404 ./...
